package com.hunliji.monitor.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.hunliji.monitor.dao.mapper.mt.BusinessTableFollowersMapper;
import com.hunliji.monitor.dao.model.dataobject.BusinessTableFollowersDO;
import com.hunliji.monitor.service.api.BusinessTableFollowersService;
import com.hunliji.monitor.service.api.model.bo.BusinessTableFollowersBO;
import com.hunliji.monitor.service.api.model.param.QueryBusinessTableFollowersParam;
import com.hunliji.monitor.share.component.ComponentLocator;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * 表记录的关注人
 * @author wuchen
 */
@Service
public class BusinessTableFollowersServiceImpl implements BusinessTableFollowersService {
    @Resource
    private BusinessTableFollowersMapper businessTableFollowersMapper;
    @Override
    public void add(BusinessTableFollowersBO businessTableFollowersBO) {
        BusinessTableFollowersDO businessTableFollowersDO = ComponentLocator.getConverter().convert(businessTableFollowersBO,BusinessTableFollowersDO.class);
        businessTableFollowersMapper.insert(businessTableFollowersDO);
    }

    @Override
    public void update(BusinessTableFollowersBO businessTableFollowersBO) {
        BusinessTableFollowersDO businessTableFollowersDO = ComponentLocator.getConverter().convert(businessTableFollowersBO,BusinessTableFollowersDO.class);
        businessTableFollowersMapper.updateById(businessTableFollowersDO);
    }

    @Override
    public List<BusinessTableFollowersBO> query(QueryBusinessTableFollowersParam queryBusinessTableFollowersParam) {

        LambdaQueryWrapper<BusinessTableFollowersDO> queryWrapper = new LambdaQueryWrapper<BusinessTableFollowersDO>();
        if(!CollectionUtils.isEmpty(queryBusinessTableFollowersParam.getRecordIdList())){
            queryWrapper.in(BusinessTableFollowersDO::getTableRecordId,queryBusinessTableFollowersParam.getRecordIdList());
        }
        queryWrapper.eq(BusinessTableFollowersDO::getDeleted,Boolean.FALSE);
        List<BusinessTableFollowersDO> businessTableFollowersDOList = businessTableFollowersMapper.selectList(queryWrapper);
        if(!CollectionUtils.isEmpty(businessTableFollowersDOList)){
            return ComponentLocator.getConverter().convertList(businessTableFollowersDOList,BusinessTableFollowersBO.class);
        }
        return new ArrayList<>();
    }
}
